import express from 'express'
import { PrismaClient } from '@prisma/client'
import cors from 'cors'
import Home from './router/home.js'
import userManage from './router/userManage.js'
import group from './router/group.js'
import roles from './router/roles.js'
import imageUpdate from './router/imageUpload.js'
import photoWall from './router/photoWall.js'
import register from './router/register.js'
import excel from './components/excel.js'
const app = express()




app.use(cors())
//配置中间件处理post请求的body参数的格式化
app.use(express.json())
app.use(express.urlencoded({extended:true}))


//如果文件是放置在express.static指定的目录
//我们可以通过服务地址直接访问这个文件, 所以一般静态文件还有上传的文件都是放置在这个目录
app.use(express.static('./public'))


const db = new PrismaClient()
app.use((req,res,next)=>{
    req.db = db
    res.success = (data,info)=>{
        res.send({ success:true ,data , info })
    }
    res.fail = (info)=>{
        res.send({ success:false ,info })
    }
    next()
})






app.use(Home)
app.use(userManage)
app.use(group)
app.use(roles)
app.use(imageUpdate)
app.use(photoWall)
app.use(register)
app.use(excel)
app.listen(3000,()=>{
    console.log('项目正常运行')
})